package team.fourth.combat.jobs;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.db.nosql.redis.RedisDS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import team.fourth.combat.commen.constant.RedisConstant;
import team.fourth.combat.commen.utils.QiniuUtils;

import java.util.Date;
import java.util.Set;

@Component
public class ClearImages {

    @Autowired
    JedisPool jedisPool;

    public void  doClear(){
        Jedis jedis = jedisPool.getResource();
        Set<String> needDeleteData = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);//数据多的key放前面
        if(CollectionUtil.isNotEmpty(needDeleteData)){
            for (String fileName : needDeleteData) {
                //删除七牛图片
                QiniuUtils.deleteFileFromQiniu(fileName);

                //删除redis
                jedis.srem(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
            }
            //TODO 里面使用批量删除
        }
        jedis.close();
    }

}
